﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.GualityGroup;
using MVC_System.DTO;
using Newtonsoft.Json;
using WMS_MAV;
using MVC_System.DTO.Delivery;
using static System.Net.WebRequestMethods;

namespace MVC_System.Controllers
{
    public class DeliveryController : Controller
    {
        private readonly IConfiguration _configuration;
        public DeliveryController(IConfiguration configuration)
        {                                            
            _configuration = configuration;
        }
        public IActionResult DeliveryAddView()
        {
            return View();
        }
        public IActionResult DeliveryShowView()
        {
            return View();
        }
        public async Task<ActionResult> DeliveryShow(DeliveryShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/Delivery/GetDelivery?deliveryNumber=" + dto.deliveryNumber + "&finishedProductNumber=" + dto.finishedProductNumber + "&statestate + dto.gualityGroupNumbering + ";
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> DeliveryAdd(DeliveryAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/Delivery/AddDelivery";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        public async Task<ActionResult> DeliveryDelete(GualityGroupDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/Delivery/DeleteDelivery";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        public IActionResult DeliveryModelView()
        {
            return View();
        }
        public async Task<ActionResult> DeliveryModel(DeliveryModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/Delivery/ModelDelivery?deliveryId=" + dto.deliveryId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public IActionResult DeliveryUpdateView()
        {
            return View();
        }
        public async Task<ActionResult> DeliveryUpdate(DeliveryUpdateDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/Delivery/UpdateDelivery";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        public async Task<ActionResult> DeliveryUpdateState(DeliveryUpdateDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/Delivery/UpdateStateDelivery";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
    }
}
